import Router from 'koa-router'
import { validator, atLeastOneParam } from '../middleware/common.middleware.ts'
import {
  getCarpoolType,
  addCarpoolType,
  editCarpoolType,
  removeCarpoolType,
} from '../controller/carpooltype.controller.ts'

const router = new Router({ prefix: '/carpooltype' })

// 查询拼车类型
router.get(
  '/get',
  validator({
    carpoolTypes: { type: 'string', min: 1, required: true },
  }),
  getCarpoolType,
)

// 新增拼车类型
router.post(
  '/add',
  validator({
    carpoolType: { type: 'string', min: 1, max: 36, required: true },
    carpoolTypeName: { type: 'string', min: 1, max: 255, required: true },
    remark: { type: 'string', max: 255, allowEmpty: true, required: false },
  }),
  addCarpoolType,
)

// 修改拼车类型
router.put(
  '/update',
  validator({
    carpoolTypeId: { type: 'string', min: 36, max: 36, required: true },
    carpoolType: {
      type: 'string',
      min: 1,
      max: 36,
      allowEmpty: true,
      required: false,
    },
    carpoolTypeName: {
      type: 'string',
      min: 1,
      max: 255,
      allowEmpty: true,
      required: false,
    },
    remark: { type: 'string', max: 255, allowEmpty: true, required: false },
  }),
  atLeastOneParam(['carpoolType', 'carpoolTypeName', 'remark']),
  editCarpoolType,
)

// 删除拼车类型
router.delete(
  '/delete/:carpoolTypeId',
  validator({
    carpoolTypeId: { type: 'string', min: 36, max: 36, required: true },
  }),
  removeCarpoolType,
)

export default router
